package cn.itsource.basic.listenter;

import cn.itsource.basic.service.IPermissionScanService;
import cn.itsource.system.mapper.PermissionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@WebListener

//申明自定义的web监听器，被容器注册和使用
public class PermissionScanInitListener implements ServletContextListener {

    @Autowired
    private IPermissionScanService permissionScanService;

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        /*WebApplicationContextUtils.getRequiredWebApplicationContext(sce
                .getServletContext())
                .getAutowireCapableBeanFactory().autowireBean(this);*/
        System.out.println("---------------------------启动前的时候就需要执行的代码");
        //开启异步线程来执行里面的业务代码 不然会存在阻塞的问题
        new Thread(new Runnable() {
            @Override
            public void run() {
                permissionScanService.scanPermission();
            }
        }).start();
    }
}